home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10676 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: newsfeed.internetmci.com!xmission!inteleNET!usenet
  2. From: langj@jcave.com (Jonathan Lang)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Using typedefs in templates (not a FAQ)
  5. Date: Sat, 09 Mar 1996 08:13:32 GMT
  6. Organization: inteleNET Internet Services
  7. Message-ID: <4hrb00$8g8@vodka.intele.net>
  8. References: <4higv6$7ih@news.hal.com>
  9. NNTP-Posting-Host: p142.jcave.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. spike@hal.com (Spike White) wrote:
  13.  
  14. >I want to typedef a new type based on the types of the formal template
  15. >parameter list.  Is that possible?
  16.  
  17. >Something like:
  18.  
  19. >template <class KEY, class NODEDATA>
  20. >class Tree {
  21. >public:
  22. >       typedef int (*pfid)(NODEDATA);
  23. >       typedef int (*pfi2c)(const KEY, const NODEDATA);
  24. >...
  25. >       pfi2c pfi_compare;  // my compare function
  26. >...
  27. >       int trav(pfid);     // perform the function on each node
  28. >...
  29. >}
  30.  
  31. This looks valid to me...
  32.  
  33. >Obviously, I could "uglify" my header file and C file by replacing the 
  34. >typedefs w/ the literal expansion, but I'd rather not do that.  And I
  35. >can't figure out a macro that would work.
  36.  
  37. >I've also considered passing these new types when instantiating, as
  38. >the 3rd and 4th formal parameters.  How would that be done?  Would it be
  39. >something like:
  40.  
  41. >template <class KEY, class NODEDATA, class int (*pfid)(NODEDATA), ... >
  42. >{
  43. >...
  44. >}
  45.  
  46. No good; a template 'class parameter' is the keyword 'class' followed
  47. by an identifier; no method for specifying further exists in the
  48. template declaration.  However, your first suggestion compiles fine on
  49. my system.  
  50.  
  51. >--
  52. >Spike White          | spike@hal.com               | Biker Nerds
  53. >HaL Software Systems | '87 BMW K75S, DoD #1347     |  From  HaL
  54. >Austin, TX           |  http://www.halsoft.com/users/spike/index.html 
  55. >Disclaimer:  HaL, want me to speak for you?  No, Dave... 
  56.  
  57. -- Jonathan Lang (langj@jcave.com)
  58.  
  59.